package com.bookstore.MapperDao;

import com.bookstore.bean.Account;
import utils.MybatisSessionFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Admin on 9/16 0016.
 */
public class AccountMapImp implements AccountMap {
    /**
     * 根据accountId 获取对应的Account 对象
     *
     * @param accountId
     * @return
     */
    public Account get(Integer accountId) {
        String statement = "com.bookstore.mapper.AccountMapper.get";
        Account account = MybatisSessionFactory.getSession().selectOne(statement, accountId);
        return account;
    }

    /**
     * 根据传入的accountId ,amount 更新指定账户余额: 扣除amount 指定的钱数
     *
     * @param accountId
     * @param amount
     */
    public void updateBalance(Integer accountId, int amount) {
        String statement = "com.bookstore.mapper.AccountMapper.updateBalance";
        Map<String, Integer> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("balance", amount);
        MybatisSessionFactory.getSession().update(statement, map);
    }
}
